//
//  NSObject+YYModel.m
//  YYKitCodeResearch
//
//  Created by songlin on 06/04/2018.
//  Copyright © 2018 songlin. All rights reserved.
//

#import "NSObject+YYModel.h"


//A class info in object model
@interface _YYModelMeta : NSObject{
    
}

@end

@implementation _YYModelMeta
- (instancetype)initWithClass:(Class)cls{
    
}
@end

@implementation NSObject (YYModel)
+ (NSDictionary *)_yy_dictionaryWithJSON:(id)json{
    if (!json || json == (id)kCFNull) return nil;
    NSDictionary *dic = nil;
    NSData *jsonData = nil;
    if ([json isKindOfClass:[NSDictionary class]]) {
        dic = json;
    }else if ([json isKindOfClass:[NSString class]]){
        jsonData = [(NSString *)json dataUsingEncoding:NSUTF8StringEncoding];
    }else if ([json isKindOfClass:[NSData class]]){
        jsonData = json;
    }
    if (jsonData) {
        dic = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:NULL];
        if (![dic isKindOfClass:[NSDictionary class]]) dic = nil;
    }
    return dic;
}
+ (instancetype)modelWithJSON:(id)json{
    NSDictionary *dic = [self _yy_dictionaryWithJSON:json];
    return [self modelWithDictionary:dic];
}

+ (instancetype)modelWithDictionary:(NSDictionary *)dictionary {
    if (!dictionary || dictionary == (id)kCFNull) return nil;
    if(![dictionary isKindOfClass:[NSDictionary class]]) return nil;
    
    Class cls = [self class];
    
    return nil;
}

@end
